<?php
$form = $this->beginWidget('CActiveForm', array(
    'enableAjaxValidation' => TRUE,
        ));
?>
    <div class="row-fluid">
        <div class="span2">
            <?php echo $this->renderPartial('_menu'); ?>
        </div>
        <div class="span10">
            <div class="widget-box">
                <div class="widget-content nopadding">
                    <div id="content-header">
                        <?php
                        $this->widget('bootstrap.widgets.TbBreadcrumbs', array(
                            'links' => array('Quản lý sản phẩm' => 'list', 'Danh mục'),
                            'htmlOptions' => array('id' => 'breadcrumb')
                        ));
                        ?>
                    </div>
                    <div id="DataTables_Table_0_wrapper" class="dataTables_wrapper" role="grid">


                        <?php
                        $this->widget('bootstrap.widgets.TbGridView', array(
                            'id' => 'table-grid',
                            'dataProvider' => $dataProvider,
                            'selectableRows' => 2,
                            'columns' => array(
                                array(
                                    'header' => '#',
                                    'class' => 'ext.CounterColumn',
                                    'htmlOptions' => array('class' => 'tdheader')
                                ),
                                array(
                                    'id' => 'autoId',
                                    'class' => 'zii.widgets.grid.CCheckBoxColumn',
                                    'selectableRows' => '50',
                                ),
                                array(
                                    'name' => 'image',
                                    'value' => '"<img src=\"".Yii::app()->request->baseUrl."/uploads/products/".$data->image."\" width=\"50\" height=\"50\"/>"',
                                    'type' => 'raw',
                                    'filter' => FALSE,
                                    'htmlOptions' => array('class' => 'tdimg')
                                ),
                                array(
                                    'name' => 'name',
                                    'type' => 'raw',
                                    'value' => '$data->name',
                                    'filter' => FALSE,
                                ),
                                array(
                                    'name' => 'price',
                                    'type' => 'raw',
                                    'value' => 'number_format($data->price, 0, ",", ".")',
                                    'filter' => FALSE,
                                ),
                                array(
                                    'name' => 'sale',
                                    'type' => 'raw',
                                    'value' => 'number_format($data->sale, 0, ",", ".")',
                                    'filter' => FALSE,
                                ),
                                array(
                                    'name' => 'create_time',
                                    'type' => 'raw',
                                    'value' => 'date("d-m-Y",$data->create_time)',
                                    'filter' => FALSE,
                                ),
                                array(
                                    'name' => 'status',
                                    'type' => 'raw',
                                    'value' => '($data->status==1)?"Kích hoạt":"Chưa kích hoạt"',
                                    'filter' => array(1 => 'Kích hoạt', 0 => 'Chưa kích hoạt'),
                                    'htmlOptions' => array('class' => 'tdstatus')
                                ),
                                array(
                                    'class' => 'CButtonColumn',
                                )
                            ),
                        ));
                        $cs = Yii::app()->getClientScript();
                        $cs->registerScript('reloadgrid', 'function reloadGrid(data){$.fn.yiiGridView.update("table-grid")}', CClientScript::POS_END);
                        ?>
                    </div>
                </div>

            </div>
        </div>
    </div>
<?php $this->endWidget(); ?>

<script>
    function status(id, status) {
        $.ajax({
            type: 'POST',
            url: 'product/status',
            data: {
                'id': id,
                'status': status
            },
            success: function(data) {
                $.fn.yiiGridView.update('table-grid');
            }
        });

    }
    function sold(id, sold) {
        $.ajax({
            type: 'POST',
            url: 'product/sold',
            data: {
                'id': id,
                'sold': sold
            },
            success: function(data) {
                $.fn.yiiGridView.update('table-grid');
            }
        });

    }

</script>